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

Side by Side 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 and built devtools docs changes. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Store settings in the local, un-synchronized repository.
6 var storage = chrome.experimental.storage.local;
7
8 // Get at the DOM controls used in the sample.
9 var resetButton = document.querySelector('button.reset');
10 var submitButton = document.querySelector('button.submit');
11 var textarea = document.querySelector('textarea');
12
13 // Load any CSS that may have previously been saved.
14 loadChanges();
15
16 submitButton.addEventListener('click', saveChanges);
17 resetButton.addEventListener('click', reset);
18
19 function saveChanges() {
20 // Get the current CSS snippet from the form.
21 var cssCode = textarea.value;
22 // Check that there's some code there.
23 if (!cssCode) {
24 message('Error: No CSS specified');
25 return;
26 }
27 // Save it locally (un-synchronized) using the Chrome extension storage API.
28 storage.set({'css': cssCode});
29 // Notify that we saved.
30 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.
31 }
32
33 function loadChanges() {
34 storage.get('css', function(items) {
35 if (items.css) {
36 textarea.value = items.css;
37 message('Loaded saved CSS.');
38 }
39 });
40 }
41
42 function reset() {
43 // Remove the saved value from storage
44 storage.remove('css', function(items) {
45 message('Reset stored CSS');
46 });
47 // Refresh the text area.
48 textarea.value = '';
49 }
50
51 function message(msg) {
52 var message = document.querySelector('.message');
53 message.innerText = msg;
54 setTimeout(function() {
55 message.innerText = '';
56 }, 3000);
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698