diff --git a/HELP.md b/HELP.md index 965bddd4..7b220094 100644 --- a/HELP.md +++ b/HELP.md @@ -234,6 +234,7 @@ All main configuration could be done via `json/config.json`. "zip" : true, /* zip text before send / unzip before save */ "notifications" : false, /* show notifications when tab is not active*/ "localStorage" : true, /* cache directory data */ + "buffer" : true, /* buffer for copying files */ "minify" : true, /* minification of js,css,html and img */ "online" : true, /* load js files from cdn or local path */ "cache" : true, /* add cache-control */ diff --git a/html/config.html b/html/config.html index 6b872b12..f8f79b97 100644 --- a/html/config.html +++ b/html/config.html @@ -7,6 +7,7 @@
  • +
  • diff --git a/html/fs/index.html b/html/fs/index.html index f35fdca4..eeefb474 100644 --- a/html/fs/index.html +++ b/html/fs/index.html @@ -52,8 +52,8 @@ client + 'load', client + 'notify', client + 'storage', - client + 'buffer', client + 'files', + client + 'buffer', 'client', client + 'listeners', client + 'key' diff --git a/json/config.json b/json/config.json index 5b91f209..bb0a7eec 100644 --- a/json/config.json +++ b/json/config.json @@ -7,6 +7,7 @@ "zip" : true, "notifications": false, "localStorage": true, + "buffer": true, "minify": true, "online": true, "cache": true, diff --git a/lib/client/buffer.js b/lib/client/buffer.js index dc3ff877..37e707db 100644 --- a/lib/client/buffer.js +++ b/lib/client/buffer.js @@ -8,12 +8,20 @@ var Util, DOM; function BufferProto() { var Storage = DOM.Storage, Dialog = DOM.Dialog, + Files = DOM.Files, Info = DOM.CurrentInfo, CLASS = 'cut-file', COPY = 'copy', - CUT = 'cut'; + CUT = 'cut', + + Buffer = { + cut : callIfEnabled.bind(null, cut), + copy : callIfEnabled.bind(null, copy), + clear : callIfEnabled.bind(null, clear), + paste : callIfEnabled.bind(null, paste) + }; function getNames() { var name = Info.name, @@ -23,7 +31,7 @@ var Util, DOM; return n ? names : [name]; } - function cut() { + function addCutClass() { var files = DOM.getSelectedFiles(), n = files.length; @@ -35,7 +43,7 @@ var Util, DOM; }); } - function clear() { + function rmCutClass() { var files = DOM.getSelectedFiles(), n = files.length; @@ -47,7 +55,23 @@ var Util, DOM; }); } - this.copy = function() { + function isEnabled(callback) { + Files.get('config', function(error, config) { + if (error) + Dialog.alert(error); + else + callback(config.buffer); + }); + } + + function callIfEnabled(callback) { + isEnabled(function(is) { + if (is) + callback(); + }); + } + + function copy() { var Storage = DOM.Storage, names = getNames(), from = Info.dirPath; @@ -57,30 +81,30 @@ var Util, DOM; from : from, names: names }); - }; + } - this.cut = function() { + function cut() { var Storage = DOM.Storage, names = getNames(), from = Info.dirPath; - cut(); + addCutClass(); Storage.remove(COPY) .set(CUT, { from : from, names: names }); - }; + } - this.clear = function() { + function clear() { Storage.remove(COPY) .remove(CUT); - clear(); - }; + rmCutClass(); + } - this.paste = function() { + function paste() { var copy = Storage.get.bind(Storage, COPY), cut = Storage.get.bind(Storage, CUT); @@ -115,6 +139,8 @@ var Util, DOM; clear(); }); - }; + } + + return Buffer; } })(Util, DOM); diff --git a/lib/client/config.js b/lib/client/config.js index e6fa8a04..8a571186 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -130,6 +130,8 @@ var CloudCmd, Util, DOM; onLocalStorageChange(data); else if (el.id === 'diff') onDiffChange(data); + else if (el.id === 'buffer') + onBufferChange(data); break; case 'number': @@ -155,15 +157,22 @@ var CloudCmd, Util, DOM; } function onLocalStorageChange(checked) { - var element = DOM.getById('diff', Element), - msg = 'Diff do not work without localStorage'; + var elDiff = DOM.getById('diff', Element), + elBuffer = DOM.getById('buffer', Element), + msg = 'Diff and Buffer do not work without localStorage'; - if (!checked && element.checked) { + if (!checked && (elDiff.checked || elBuffer.checked)) { alert(msg); - element.checked = false; + elDiff.checked = + elBuffer.checked = false; + onChange({ - target: element + target: elDiff + }); + + onChange({ + target: elBuffer }); } } @@ -178,6 +187,16 @@ var CloudCmd, Util, DOM; return element.checked; } + function onBufferChange(checked) { + var element = DOM.getById('localStorage', Element); + + if (!element.checked && checked) { + onLocalStorageChange(element.checked); + } + + return element.checked; + } + function onKey(event) { var keyCode = event.keyCode, ESC = Key.ESC;