From 97c74d8542d5c14d9e4e0f4cdf97f8566ace1eae Mon Sep 17 00:00:00 2001 From: boyska Date: Sat, 16 Nov 2019 12:31:14 +0100 Subject: [PATCH] js: debounce name change --- server/pages/new.html | 1 + server/static/js/new.js | 7 ++++--- server/static/js/underscore-min.js | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 server/static/js/underscore-min.js diff --git a/server/pages/new.html b/server/pages/new.html index 379297c..dc6b291 100644 --- a/server/pages/new.html +++ b/server/pages/new.html @@ -13,6 +13,7 @@ + diff --git a/server/static/js/new.js b/server/static/js/new.js index a514bac..bfcfa86 100644 --- a/server/static/js/new.js +++ b/server/static/js/new.js @@ -1,4 +1,4 @@ -/*global $, config, RecAPI, poll_job*/ +/*global $, config, RecAPI, poll_job, _*/ //TODO: move to a separate file(?) $.widget("ror.countclock", { @@ -82,7 +82,8 @@ $.widget("ror.ongoingrec", { ); this._update(); - view.on("change keydown paste input", "input", function(evt) { + view.on("change keydown paste input", "input", + _.debounce(function onNameChanged(evt) { console.log('change', evt); var prevrec = widget.options.rec; prevrec.name = $(evt.target).val(); @@ -90,7 +91,7 @@ $.widget("ror.ongoingrec", { widget._trigger("change", evt, {rec: rec, widget: widget, changed: {name: rec.name}} ); - }); + }, 500)); view.on("click", ".rec-stop", function(evt) { widget._trigger("stop", evt, {rec: rec, widget: widget}); }); diff --git a/server/static/js/underscore-min.js b/server/static/js/underscore-min.js new file mode 100644 index 0000000..f2a20a5 --- /dev/null +++ b/server/static/js/underscore-min.js @@ -0,0 +1,5 @@ +// Underscore.js 1.9.1 +// http://underscorejs.org +// (c) 2009-2018 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +// Underscore may be freely distributed under the MIT license. +!function(){var n="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this||{},r=n._,e=Array.prototype,o=Object.prototype,s="undefined"!=typeof Symbol?Symbol.prototype:null,u=e.push,c=e.slice,p=o.toString,i=o.hasOwnProperty,t=Array.isArray,a=Object.keys,l=Object.create,f=function(){},h=function(n){return n instanceof h?n:this instanceof h?void(this._wrapped=n):new h(n)};"undefined"==typeof exports||exports.nodeType?n._=h:("undefined"!=typeof module&&!module.nodeType&&module.exports&&(exports=module.exports=h),exports._=h),h.VERSION="1.9.1";var v,y=function(u,i,n){if(void 0===i)return u;switch(null==n?3:n){case 1:return function(n){return u.call(i,n)};case 3:return function(n,r,t){return u.call(i,n,r,t)};case 4:return function(n,r,t,e){return u.call(i,n,r,t,e)}}return function(){return u.apply(i,arguments)}},d=function(n,r,t){return h.iteratee!==v?h.iteratee(n,r):null==n?h.identity:h.isFunction(n)?y(n,r,t):h.isObject(n)&&!h.isArray(n)?h.matcher(n):h.property(n)};h.iteratee=v=function(n,r){return d(n,r,1/0)};var g=function(u,i){return i=null==i?u.length-1:+i,function(){for(var n=Math.max(arguments.length-i,0),r=Array(n),t=0;t":">",'"':""","'":"'","`":"`"},P=h.invert(L),W=function(r){var t=function(n){return r[n]},n="(?:"+h.keys(r).join("|")+")",e=RegExp(n),u=RegExp(n,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};h.escape=W(L),h.unescape=W(P),h.result=function(n,r,t){h.isArray(r)||(r=[r]);var e=r.length;if(!e)return h.isFunction(t)?t.call(n):t;for(var u=0;u/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var J=/(.)^/,U={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},V=/\\|'|\r|\n|\u2028|\u2029/g,$=function(n){return"\\"+U[n]};h.template=function(i,n,r){!n&&r&&(n=r),n=h.defaults({},n,h.templateSettings);var t,e=RegExp([(n.escape||J).source,(n.interpolate||J).source,(n.evaluate||J).source].join("|")+"|$","g"),o=0,a="__p+='";i.replace(e,function(n,r,t,e,u){return a+=i.slice(o,u).replace(V,$),o=u+n.length,r?a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":t?a+="'+\n((__t=("+t+"))==null?'':__t)+\n'":e&&(a+="';\n"+e+"\n__p+='"),n}),a+="';\n",n.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{t=new Function(n.variable||"obj","_",a)}catch(n){throw n.source=a,n}var u=function(n){return t.call(this,n,h)},c=n.variable||"obj";return u.source="function("+c+"){\n"+a+"}",u},h.chain=function(n){var r=h(n);return r._chain=!0,r};var G=function(n,r){return n._chain?h(r).chain():r};h.mixin=function(t){return h.each(h.functions(t),function(n){var r=h[n]=t[n];h.prototype[n]=function(){var n=[this._wrapped];return u.apply(n,arguments),G(this,r.apply(h,n))}}),h},h.mixin(h),h.each(["pop","push","reverse","shift","sort","splice","unshift"],function(r){var t=e[r];h.prototype[r]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!==r&&"splice"!==r||0!==n.length||delete n[0],G(this,n)}}),h.each(["concat","join","slice"],function(n){var r=e[n];h.prototype[n]=function(){return G(this,r.apply(this._wrapped,arguments))}}),h.prototype.value=function(){return this._wrapped},h.prototype.valueOf=h.prototype.toJSON=h.prototype.value,h.prototype.toString=function(){return String(this._wrapped)},"function"==typeof define&&define.amd&&define("underscore",[],function(){return h})}(); \ No newline at end of file