Skip to content

Commit

Permalink
Prevent multiple JS instance creation where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixx committed May 22, 2024
1 parent 16f3c76 commit d370c48
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 31 deletions.
9 changes: 4 additions & 5 deletions js/src/bundles/protected.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ import {Sidebar} from '../sidebar.js';
import {PersonalTools} from '../personaltools.js';

export * from '../batcheditems.js';
export * from '../colormode.js';
export * from '../copysupport.js';
export * from '../keybinder.js';
export * from '../keybinder.js';
export * from '../personaltools.js';
export * from '../referencebrowser.js';
export * from '../scrollbar.js';
export * from '../selectable.js';
export * from '../sharing.js';
export * from '../sidebar.js';
export * from '../tabletoolbar.js';
export * from '../translation.js';
export * from '../utils.js';
export * from '../colormode.js';
export * from '../scrollbar.js';
export * from '../sidebar.js';
export * from '../personaltools.js';

$(function() {
new KeyBinder();
Expand Down
12 changes: 6 additions & 6 deletions js/src/cone.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import * as batcheditems from './batcheditems.js';
import * as colormode from './colormode.js';
import * as copysupport from './copysupport.js';
import * as keybinder from './keybinder.js';
import * as livesearch from './livesearch.js';
import * as personaltools from './personaltools.js';
import * as referencebrowser from './referencebrowser.js';
import * as selectable from './selectable.js';
import * as settingstabs from './settingstabs.js';
import * as sharing from './sharing.js';
import * as sidebar from './sidebar.js';
import * as tabletoolbar from './tabletoolbar.js';
import * as utils from './utils.js';
import * as colormode from './colormode.js';
import * as sidebar from './sidebar.js';
import * as personaltools from './personaltools.js';

let api = {};

Object.assign(api, batcheditems);
Object.assign(api, colormode);
Object.assign(api, copysupport);
Object.assign(api, keybinder);
Object.assign(api, livesearch);
Object.assign(api, personaltools);
Object.assign(api, referencebrowser);
Object.assign(api, selectable);
Object.assign(api, settingstabs);
Object.assign(api, sharing);
Object.assign(api, sidebar);
Object.assign(api, tabletoolbar);
Object.assign(api, utils);
Object.assign(api, colormode);
Object.assign(api, sidebar);
Object.assign(api, personaltools);

let cone = api;
export default cone;
3 changes: 1 addition & 2 deletions js/src/keybinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export let keys = {

/**
* XXX: Use ``ts.KeyState`` instead.
* Need a mechanism to attach and unload instances with ``ts.ajax`` first.
*/
export class KeyBinder {

Expand All @@ -31,7 +30,7 @@ export class KeyBinder {
switch (e.keyCode || e.which) {
case 16:
keys.shift_down = false;
break;
break;
case 17:
keys.ctrl_down = false;
break;
Expand Down
5 changes: 2 additions & 3 deletions js/src/livesearch.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import $ from 'jquery';
import ts from 'treibstoff';

export class LiveSearch {

static initialize(context, factory=null) {
let elem = $('input#search-text', context);
if (!elem.length) {
const elem = ts.query_elem('input#search-text', context);
if (!elem) {
return;
}
if (factory === null) {
Expand Down
4 changes: 2 additions & 2 deletions js/src/personaltools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ts from 'treibstoff';
export class PersonalTools extends ts.Events {

static initialize(context) {
const elem = $('#header-main', context);
if (!elem.length) {
const elem = ts.query_elem('#header-main', context);
if (!elem) {
return;
}
new PersonalTools(elem);
Expand Down
10 changes: 7 additions & 3 deletions js/src/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import ts from 'treibstoff';
export class Sidebar extends ts.Motion {

static initialize(context) {
new Sidebar(context);
const elem = ts.query_elem('#sidebar_left', context);
if (!elem) {
return;
}
new Sidebar(context, elem);
}

constructor(context) {
constructor(context, elem) {
super();
this.elem = $('#sidebar_left', context);
this.elem = elem;
this.resizer_elem = $('#sidebar_resizer', context);
this.collapse_elem = $('#sidebar_collapse', context);

Expand Down
16 changes: 10 additions & 6 deletions src/cone/app/browser/static/cone/cone.app.protected.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ var cone_app_protected = (function (exports, $, ts) {
switch (e.keyCode || e.which) {
case 16:
keys.shift_down = false;
break;
break;
case 17:
keys.ctrl_down = false;
break;
Expand Down Expand Up @@ -764,11 +764,15 @@ var cone_app_protected = (function (exports, $, ts) {

class Sidebar extends ts.Motion {
static initialize(context) {
new Sidebar(context);
const elem = ts.query_elem('#sidebar_left', context);
if (!elem) {
return;
}
new Sidebar(context, elem);
}
constructor(context) {
constructor(context, elem) {
super();
this.elem = $('#sidebar_left', context);
this.elem = elem;
this.resizer_elem = $('#sidebar_resizer', context);
this.collapse_elem = $('#sidebar_collapse', context);
this.on_click = this.on_click.bind(this);
Expand Down Expand Up @@ -821,8 +825,8 @@ var cone_app_protected = (function (exports, $, ts) {

class PersonalTools extends ts.Events {
static initialize(context) {
const elem = $('#header-main', context);
if (!elem.length) {
const elem = ts.query_elem('#header-main', context);
if (!elem) {
return;
}
new PersonalTools(elem);
Expand Down
2 changes: 1 addition & 1 deletion src/cone/app/browser/static/cone/cone.app.protected.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cone/app/browser/static/cone/cone.app.public.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var cone_app_public = (function (exports, $, ts) {

class LiveSearch {
static initialize(context, factory=null) {
let elem = $('input#search-text', context);
if (!elem.length) {
const elem = ts.query_elem('input#search-text', context);
if (!elem) {
return;
}
if (factory === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/cone/app/browser/static/cone/cone.app.public.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d370c48

Please sign in to comment.