Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/234609

Change subject: Add more config methods and implement in standalone using 
localStorage
......................................................................

Add more config methods and implement in standalone using localStorage

Add setConfig, and make ve.config switch between getting and setting
based on arguments.

Change-Id: I5704a0e3e08291903e960235f57243b2da147901
---
M src/init/sa/ve.init.sa.Platform.js
M src/init/ve.init.Platform.js
M src/ve.utils.js
3 files changed, 54 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/09/234609/1

diff --git a/src/init/sa/ve.init.sa.Platform.js 
b/src/init/sa/ve.init.sa.Platform.js
index f4c82a4..0e435d5 100644
--- a/src/init/sa/ve.init.sa.Platform.js
+++ b/src/init/sa/ve.init.sa.Platform.js
@@ -69,6 +69,39 @@
  */
 ve.init.sa.Platform.prototype.getMessage = $.i18n;
 
+/**
+ * @inheritdoc
+ */
+ve.init.sa.Platform.prototype.getConfig = function ( keys ) {
+       var i, l, values;
+       if ( Array.isArray( keys ) ) {
+               values = {};
+               for ( i = 0, l = keys.length; i < l; i++ ) {
+                       values[keys[i]] = this.getConfig( keys[i] );
+               }
+       } else {
+               return JSON.parse( localStorage.getItem( 've-' + keys ) );
+       }
+       return values;
+};
+
+/**
+ * @inheritdoc
+ */
+ve.init.sa.Platform.prototype.setConfig = function ( keyOrValueMap, value ) {
+       var i;
+       if ( typeof keyOrValueMap === 'object' ) {
+               for ( i in keyOrValueMap ) {
+                       if ( keyOrValueMap.hasOwnProperty( i ) ) {
+                               this.setConfig( i, keyOrValueMap[i] );
+                       }
+               }
+       } else {
+               localStorage.setItem( 've-' + keyOrValueMap, JSON.stringify( 
value ) );
+       }
+       return true;
+};
+
 /** @inheritdoc */
 ve.init.sa.Platform.prototype.addParsedMessages = function ( messages ) {
        var key;
diff --git a/src/init/ve.init.Platform.js b/src/init/ve.init.Platform.js
index 9622457..23231ea 100644
--- a/src/init/ve.init.Platform.js
+++ b/src/init/ve.init.Platform.js
@@ -129,6 +129,16 @@
 ve.init.Platform.prototype.getConfig = null;
 
 /**
+ * Get a config value from the platform.
+ *
+ * @method
+ * @abstract
+ * @param {string|Object} keyOrValueMap Key to set value for, or object 
mapping keys to values
+ * @param {Mixed} [value] Value to set (optional, only in use when key is a 
string)
+ */
+ve.init.Platform.prototype.setConfig = null;
+
+/**
  * Add multiple messages to the localization system.
  *
  * @method
diff --git a/src/ve.utils.js b/src/ve.utils.js
index 1c9748e..be56686 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -412,15 +412,21 @@
 };
 
 /**
- * Get a config value.
+ * Get or set a config value.
  *
- * @param {string|string[]} key Config key, or list of keys
- * @return {Mixed|Object} Config value, or keyed object of config values if 
list of keys provided
+ * @param {string|string[]|Object} key Config key, list of keys or object 
mapping keys to values
+ * @param {Mixed} [value] Value to set, if setting and key is a string
+ * @return {Mixed|Object|boolean} Config value, keyed object of config values 
if list of keys provided,
+ *  or success boolean if setting.
  */
-ve.config = function () {
+ve.config = function ( key, value ) {
        // Avoid using bind because ve.init.platform doesn't exist yet.
        // TODO: Fix dependency issues between ve.js and ve.init.platform
-       return ve.init.platform.getConfig.apply( ve.init.platform, arguments );
+       if ( value === undefined && ( typeof key === 'string' || Array.isArray( 
key ) ) ) {
+               return ve.init.platform.getConfig.apply( ve.init.platform, 
arguments );
+       } else {
+               return ve.init.platform.setConfig.apply( ve.init.platform, 
arguments );
+       }
 };
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/234609
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5704a0e3e08291903e960235f57243b2da147901
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to