Skip to content

Commit

Permalink
Make JS files valid
Browse files Browse the repository at this point in the history
  • Loading branch information
r0x0r committed Oct 10, 2024
1 parent 83d972c commit a3ca092
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion webview/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ window.pywebview = {
}
}

window.pywebview._createApi(%(func_list)s);
window.pywebview._createApi(JSON.parse('%(func_list)s'));
8 changes: 4 additions & 4 deletions webview/js/customize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

(function() {
var platform = window.pywebview.platform;
var disableText = %(text_select)s;
var disableText = '%(text_select)s' === 'False';
var disableTextCss = 'body {-webkit-user-select: none; -khtml-user-select: none; -ms-user-select: none; user-select: none; cursor: default;}'

if (platform == 'mshtml') {
Expand Down Expand Up @@ -64,11 +64,11 @@
dragBlocks[i].addEventListener('mousedown', onMouseDown);
}
// easy drag for edge chromium
if (%(easy_drag)s) {
if ('%(easy_drag)s' === 'True') {
window.addEventListener('mousedown', onMouseDown);
}

if (!%(zoomable)s) {
if ('%(zoomable)s' === 'False') {
document.body.addEventListener('touchstart', function(e) {
if ((e.touches.length > 1) || e.targetTouches.length > 1) {
e.preventDefault();
Expand All @@ -85,7 +85,7 @@
}

// draggable
if (!%(draggable)s) {
if ('%(draggable)s' === 'False') {
Array.prototype.slice.call(document.querySelectorAll("img")).forEach(function(img) {
img.setAttribute("draggable", false);
})
Expand Down
9 changes: 4 additions & 5 deletions webview/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def generate_func():
def js_bridge_call(window: Window, func_name: str, param: Any, value_id: str) -> None:
def _call():
try:
print(func_params)
result = func(*func_params)
result = json.dumps(result).replace('\\', '\\\\').replace("'", "\\'")
code = f'window.pywebview._returnValues["{func_name}"]["{value_id}"] = {{value: \'{result}\'}}'
Expand Down Expand Up @@ -286,15 +285,15 @@ def load_js_files(window: Window, func_list, platform: str) -> str:
'token': _TOKEN,
'platform': platform,
'uid': window.uid,
'func_list': func_list,
'func_list': json.dumps(func_list),
'js_api_endpoint': window.js_api_endpoint,
}
elif name == 'customize':
params = {
'text_select': str(not window.text_select).lower(),
'text_select': str(not window.text_select),
'drag_selector': webview.DRAG_REGION_SELECTOR,
'zoomable': str(window.zoomable).lower(),
'draggable': str(window.draggable).lower(),
'zoomable': str(window.zoomable),
'draggable': str(window.draggable),
'easy_drag': str(platform == 'chromium' and window.easy_drag and window.frameless).lower(),
}
elif name == 'polyfill' and platform != 'mshtml':
Expand Down

0 comments on commit a3ca092

Please sign in to comment.