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

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

Issue 9691033: Update the Stylizr example to work with the manifest changes the Storage API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Store settings in the synchronized repository. 5 // Store settings in the synchronized repository.
6 var storage = chrome.storage.sync; 6 var storage = chrome.storage.sync;
7 7
8 // Get at the DOM controls used in the sample. 8 // Get at the DOM controls used in the sample.
9 var resetButton = document.querySelector('button.reset'); 9 var resetButton = document.querySelector('button.reset');
10 var submitButton = document.querySelector('button.submit'); 10 var submitButton = document.querySelector('button.submit');
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 // Save it using the Chrome extension storage API. 27 // Save it using the Chrome extension storage API.
28 storage.set({'css': cssCode}, function() { 28 storage.set({'css': cssCode}, function() {
29 // Notify that we saved. 29 // Notify that we saved.
30 message('Settings saved'); 30 message('Settings saved');
31 }); 31 });
32 } 32 }
33 33
34 function loadChanges() { 34 function loadChanges() {
35 storage.get('css', function(items) { 35 storage.get('css', function(items) {
36 // To avoid checking items.css we could specify storage.get({css: ''}) to
37 // return a default value of '' if there is no css value yet.
36 if (items.css) { 38 if (items.css) {
37 textarea.value = items.css; 39 textarea.value = items.css;
38 message('Loaded saved CSS.'); 40 message('Loaded saved CSS.');
39 } 41 }
40 }); 42 });
41 } 43 }
42 44
43 function reset() { 45 function reset() {
44 // Remove the saved value from storage 46 // Remove the saved value from storage. storage.clear would achieve the same
47 // thing.
45 storage.remove('css', function(items) { 48 storage.remove('css', function(items) {
46 message('Reset stored CSS'); 49 message('Reset stored CSS');
47 }); 50 });
48 // Refresh the text area. 51 // Refresh the text area.
49 textarea.value = ''; 52 textarea.value = '';
50 } 53 }
51 54
52 function message(msg) { 55 function message(msg) {
53 var message = document.querySelector('.message'); 56 var message = document.querySelector('.message');
54 message.innerText = msg; 57 message.innerText = msg;
55 setTimeout(function() { 58 setTimeout(function() {
56 message.innerText = ''; 59 message.innerText = '';
57 }, 3000); 60 }, 3000);
58 } 61 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/examples/api/storage/stylizr/manifest.json ('k') | chrome/common/extensions/docs/samples.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698