Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1975)

Unified Diff: chrome/common/extensions/docs/examples/api/storage/stylizr/options.js

Issue 8916013: Added storage sample. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Storage sample Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/examples/api/storage/stylizr/options.js
diff --git a/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js
new file mode 100644
index 0000000000000000000000000000000000000000..4eeab8f34bfdfb1eda7e4869919fb67895cee711
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js
@@ -0,0 +1,58 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Store settings in the synchronized repository.
+var storage = chrome.experimental.storage.sync;
+
+// Get at the DOM controls used in the sample.
+var resetButton = document.querySelector('button.reset');
+var submitButton = document.querySelector('button.submit');
+var textarea = document.querySelector('textarea');
+
+// Load any CSS that may have previously been saved.
+loadChanges();
+
+submitButton.addEventListener('click', saveChanges);
+resetButton.addEventListener('click', reset);
+
+function saveChanges() {
+ // Get the current CSS snippet from the form.
+ var cssCode = textarea.value;
+ // Check that there's some code there.
+ if (!cssCode) {
+ message('Error: No CSS specified');
+ return;
+ }
+ // Save it locally (un-synchronized) using the Chrome extension storage API.
+ storage.set({'css': cssCode}, function() {
+ // Notify that we saved.
+ message('Settings saved');
+ });
+}
+
+function loadChanges() {
+ storage.get('css', function(items) {
+ if (items.css) {
+ textarea.value = items.css;
+ message('Loaded saved CSS.');
+ }
+ });
+}
+
+function reset() {
+ // Remove the saved value from storage
+ storage.remove('css', function(items) {
+ message('Reset stored CSS');
+ });
+ // Refresh the text area.
+ textarea.value = '';
+}
+
+function message(msg) {
+ var message = document.querySelector('.message');
+ message.innerText = msg;
+ setTimeout(function() {
+ message.innerText = '';
+ }, 3000);
+}

Powered by Google App Engine
This is Rietveld 408576698