Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: files/preferences.js

Issue 8483154: Adding ABP core modules to ABP/Opera (Closed)
Patch Set: Created Oct. 11, 2012, 9:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 const preferences = {
2 string: function(key, value) { //Gets or sets a string value
3 if(value == undefined) //Gets
4 return widget.preferences.getItem(key);
5 else //Sets
6 widget.preferences.setItem(key, value);
7 },
8 bool: function(key, value) { //Gets or sets a bool value
9 if(value == undefined) { //Gets
10 switch(widget.preferences.getItem(key)) {
11 case 'true':
12 return true;
13 break;
14 default: //Returns false if the value doesn't ex ist
15 return false;
16 break;
17 }
18 }
19 else { //Sets
20 if(value)
21 widget.preferences.setItem(key, 'true');
22 else
23 this.remove(key); //When set to false, remove th e key to save space
24 }
25 },
26 int: function(key, value) { //Gets or sets a int value
27 if(value == undefined) { //Gets
28 value = parseInt(widget.preferences.getItem(key));
29 if(value == NaN)
30 return 0; //On error return 0
31 else
32 return value;
33 }
34 else //Sets
35 widget.preferences.setItem(key, value);
36 },
37 float: function(key, value) { //Gets or sets a float value
38 if(value == undefined) { //Gets
39 value = parseFloat(widget.preferences.getItem(key));
40 if(value == NaN)
41 return 0; //On error return 0
42 else
43 return value;
44 }
45 else //Sets
46 widget.preferences.setItem(key, value);
47 },
48 array: function(key, value) { //Gets or sets an array in the preferences
49 if(value == undefined) { //Gets
50 if(this.exist(key)) {
51 value = widget.preferences.getItem(key);
52 if(value.indexOf("\n") > -1)
53 return value.split("\n");
54 else {
55 return [value];
56 }
57 }
58 return new Array(); //Returns an empty array when no val ue exists
59 }
60 else if(value instanceof Array) { //Sets
61 value = value.join("\n");
62 widget.preferences.setItem(key, value);
63 }
64 },
65 invert: function(key) { //Inverts a true/false setting
66 switch(widget.preferences.getItem(key)) {
67 case 'true':
68 widget.preferences.setItem(key, 'false');
69 break;
70 default:
71 widget.preferences.setItem(key, 'true');
72 break;
73 }
74 },
75 exist: function(key) { //Says if a preference exists
76 if(widget.preferences.getItem(key) != null && widget.preferences .getItem(key) != '')
77 return true;
78 return false;
79 },
80 remove: function(key) {
81 widget.preferences.removeItem(key);
82 }
83 };
OLDNEW

Powered by Google App Engine
This is Rietveld