Commit 62096fda authored by Guillaume's avatar Guillaume

Fix and enforce eslint rules

Also fix an issue in _target-counters.js_ where `psuedo` was misspelled and undefined in the `else` clause.
parent e6492476
......@@ -48,7 +48,7 @@
"pretest": "npm run build",
"prepublishOnly": "npm run build && npm run compile && npm run legacy",
"watch": "./node_modules/.bin/rollup -w -c",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src; exit 0",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src",
"docker": "docker build -t pagedmedia/pagedjs . && docker run -it --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test"
},
"repository": {
......
import Chunker from './chunker.js';
/* global describe, it, expect */
import Chunker from "./chunker.js";
describe('Chunker', async () => {
describe("Chunker", async () => {
it('should create a page area', async () => {
let chunker = new Chunker();
chunker.setup();
expect(chunker.pagesArea.classList).toContain('pagedjs_pages');
})
it("should create a page area", async () => {
let chunker = new Chunker();
chunker.setup();
expect(chunker.pagesArea.classList).toContain("pagedjs_pages");
});
})
});
......@@ -80,7 +80,7 @@ class Page {
// page.dataset.pageNumber = index;
page.dataset.pageNumber = index;
page.setAttribute('id', id);
page.setAttribute("id", id);
if (this.name) {
page.classList.add("pagedjs_" + this.name + "_page");
......
......@@ -92,6 +92,10 @@ class TargetCounters extends Handler {
let selector = UUID();
selected.setAttribute("data-" + target.variable, selector);
// TODO: handle other counter types (by query)
let pseudo = "";
if (split.length > 1) {
pseudo += "::" + split[1];
}
if (target.counter === "page") {
let pages = chunker.pagesArea.querySelectorAll(".pagedjs_page");
let pg = 0;
......@@ -109,15 +113,11 @@ class TargetCounters extends Handler {
}
}
let psuedo = "";
if (split.length > 1) {
psuedo += "::" + split[1];
}
this.styleSheet.insertRule(`[data-${target.variable}="${selector}"]${psuedo} { counter-reset: ${target.variable} ${pg}; }`, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(`[data-${target.variable}="${selector}"]${pseudo} { counter-reset: ${target.variable} ${pg}; }`, this.styleSheet.cssRules.length);
} else {
let value = element.getAttribute(`data-counter-${target.counter}-value`);
if (value) {
this.styleSheet.insertRule(`[data-${target.variable}="${selector}"]${psuedo} { counter-reset: ${target.variable} ${target.variable} ${parseInt(value)}; }`, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(`[data-${target.variable}="${selector}"]${pseudo} { counter-reset: ${target.variable} ${target.variable} ${parseInt(value)}; }`, this.styleSheet.cssRules.length);
}
}
}
......
......@@ -16,7 +16,7 @@ class Lists extends Handler {
var orderedLists = pageElement.getElementsByTagName("ol");
for (var list of orderedLists) {
if (list.hasChildNodes()) {
list.start = list.firstElementChild.dataset.itemNum;
list.start = list.firstElementChild.dataset.itemNum;
}
else {
list.parentNode.removeChild(list);
......
......@@ -57,25 +57,25 @@ class Hook {
return Promise.all(promises);
}
/**
/**
* Triggers a hook to run all functions synchronously
* @example this.content.trigger(args).then(function(){...});
* @return {Array} results
*/
triggerSync(){
var args = arguments;
var context = this.context;
var results = [];
triggerSync(){
var args = arguments;
var context = this.context;
var results = [];
this.hooks.forEach(function(task) {
var executing = task.apply(context, args);
this.hooks.forEach(function(task) {
var executing = task.apply(context, args);
results.push(executing);
});
results.push(executing);
});
return results;
}
return results;
}
// Adds a function to be run before a hook completes
list(){
......
......@@ -2,17 +2,17 @@ export default async function request(url, options={}) {
return new Promise(function(resolve, reject) {
let request = new XMLHttpRequest();
request.open(options.method || 'get', url, true);
request.open(options.method || "get", url, true);
for (let i in options.headers) {
request.setRequestHeader(i, options.headers[i]);
}
request.withCredentials = options.credentials=='include';
request.withCredentials = options.credentials === "include";
request.onload = () => {
// Chrome returns a status code of 0 for local files
const status = request.status === 0 && url.startsWith('file://') ? 200 : request.status;
// Chrome returns a status code of 0 for local files
const status = request.status === 0 && url.startsWith("file://") ? 200 : request.status;
resolve(new Response(request.responseText, {status}));
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment