From bb107b20db04a5c19842c1e27003de70d0aa0dfe Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Thu, 30 Apr 2020 10:04:52 +0100 Subject: [PATCH] - debounce browser resize events to 1 per second --- package-lock.json | 13 +++++++++---- package.json | 5 +++-- perguntations/static/js/detect_unfocus.js | 18 ++---------------- perguntations/static/underscore | 1 + perguntations/templates/test.html | 1 + 5 files changed, 16 insertions(+), 22 deletions(-) create mode 120000 perguntations/static/underscore diff --git a/package-lock.json b/package-lock.json index 539b10c..649d71c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,16 +13,16 @@ "integrity": "sha512-tbx5cHubwE6e2ZG7nqM3g/FZ5PQEDMWmMGNrCUBVRPHXTJaH7CBDdsLeu3eCh3B1tzAxTnAbtmrzvWEvT2NNEA==" }, "codemirror": { - "version": "5.52.2", - "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.52.2.tgz", - "integrity": "sha512-WCGCixNUck2HGvY8/ZNI1jYfxPG5cRHv0VjmWuNzbtCLz8qYA5d+je4QhSSCtCaagyeOwMi/HmmPTjBgiTm2lQ==" + "version": "5.53.2", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.53.2.tgz", + "integrity": "sha512-wvSQKS4E+P8Fxn/AQ+tQtJnF1qH5UOlxtugFLpubEZ5jcdH2iXTVinb+Xc/4QjshuOxRm4fUsU2QPF1JJKiyXA==" }, "datatables": { "version": "1.10.18", "resolved": "https://registry.npmjs.org/datatables/-/datatables-1.10.18.tgz", "integrity": "sha512-ntatMgS9NN6UMpwbmO+QkYJuKlVeMA2Mi0Gu/QxyIh+dW7ZjLSDhPT2tWlzjpIWEkDYgieDzS9Nu7bdQCW0sbQ==", "requires": { - "jquery": "3.5.0" + "jquery": ">=1.7" } }, "jquery": { @@ -39,6 +39,11 @@ "version": "1.16.1", "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==" + }, + "underscore": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz", + "integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==" } } } diff --git a/package.json b/package.json index 230fd55..b0423c8 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.13.0", "bootstrap": "^4.4.1", - "codemirror": "^5.52.2", + "codemirror": "^5.53.2", "datatables": "^1.10", "jquery": "^3.5.0", "mathjax": "^3.0.5", - "popper.js": "^1.16.1" + "popper.js": "^1.16.1", + "underscore": "^1.10" } } diff --git a/perguntations/static/js/detect_unfocus.js b/perguntations/static/js/detect_unfocus.js index f109e84..aceb763 100644 --- a/perguntations/static/js/detect_unfocus.js +++ b/perguntations/static/js/detect_unfocus.js @@ -31,24 +31,10 @@ $(document).ready(function() { }); }); - $(window).resize(function(){ + $(window).resize(_.debounce(function(){ $.postJSON("/studentwebservice", { "cmd": "size", "value": JSON.stringify([screen.height, screen.width, $(window).height(), $(window).width()]), }); - - - // // var n = $(window).scrollTop(); - // $.postJSON({"/studentwebservice", { - // "cmd": "size", - // "value": JSON.stringify([screen.height, screen.width, $(window).height(), $(window).width()]), - // }}); - // // data: { - // // "cmd": "resize", - // // "name": $("#number").text(), - // // "scroll": n - // // } - // // }); - }); - + }, 1000)); }); diff --git a/perguntations/static/underscore b/perguntations/static/underscore new file mode 120000 index 0000000..34604b0 --- /dev/null +++ b/perguntations/static/underscore @@ -0,0 +1 @@ +../../node_modules/underscore \ No newline at end of file diff --git a/perguntations/templates/test.html b/perguntations/templates/test.html index e117f0c..bc38c36 100644 --- a/perguntations/templates/test.html +++ b/perguntations/templates/test.html @@ -24,6 +24,7 @@ + -- libgit2 0.21.2