Chromium Code Reviews| 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..5b2008190e4952c47fa5a57b54b4e91072070a32 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/examples/api/storage/stylizr/options.js |
| @@ -0,0 +1,57 @@ |
| +// 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 local, un-synchronized repository. |
| +var storage = chrome.experimental.storage.local; |
| + |
| +// 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}); |
| + // Notify that we saved. |
| + message('Settings saved'); |
|
not at google - send to devlin
2011/12/14 23:04:13
Should probably do this in the callback from set()
Boris Smus
2011/12/14 23:29:35
Done.
|
| +} |
| + |
| +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); |
| +} |