Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
committerFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
commitaaa9509d120524573085e94af9de5cdde83e3271 (patch)
tree3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/autosave.js
parent56b79181adc0bd6e9abef97ea075c14be971a01a (diff)
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/autosave.js')
-rw-r--r--app/assets/javascripts/autosave.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/assets/javascripts/autosave.js b/app/assets/javascripts/autosave.js
new file mode 100644
index 00000000000..7116512d6b7
--- /dev/null
+++ b/app/assets/javascripts/autosave.js
@@ -0,0 +1,63 @@
+(function() {
+ this.Autosave = (function() {
+ function Autosave(field, key) {
+ this.field = field;
+ if (key.join != null) {
+ key = key.join("/");
+ }
+ this.key = "autosave/" + key;
+ this.field.data("autosave", this);
+ this.restore();
+ this.field.on("input", (function(_this) {
+ return function() {
+ return _this.save();
+ };
+ })(this));
+ }
+
+ Autosave.prototype.restore = function() {
+ var e, error, text;
+ if (window.localStorage == null) {
+ return;
+ }
+ try {
+ text = window.localStorage.getItem(this.key);
+ } catch (error) {
+ e = error;
+ return;
+ }
+ if ((text != null ? text.length : void 0) > 0) {
+ this.field.val(text);
+ }
+ return this.field.trigger("input");
+ };
+
+ Autosave.prototype.save = function() {
+ var text;
+ if (window.localStorage == null) {
+ return;
+ }
+ text = this.field.val();
+ if ((text != null ? text.length : void 0) > 0) {
+ try {
+ return window.localStorage.setItem(this.key, text);
+ } catch (undefined) {}
+ } else {
+ return this.reset();
+ }
+ };
+
+ Autosave.prototype.reset = function() {
+ if (window.localStorage == null) {
+ return;
+ }
+ try {
+ return window.localStorage.removeItem(this.key);
+ } catch (undefined) {}
+ };
+
+ return Autosave;
+
+ })();
+
+}).call(this);